home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 263 / DPCS0110.ISO / Assets / Interface / Main.dxr / Flash Components_1_Centre pane.swf / scripts / __Packages / TextPage.as < prev   
Encoding:
Text File  |  2005-05-18  |  7.2 KB  |  203 lines

  1. class TextPage extends mx.core.UIObject
  2. {
  3.    var __title;
  4.    var __body;
  5.    var dispatchEvent;
  6.    static var symbolName = "TextPage";
  7.    static var symbolOwner = TextPage;
  8.    var className = "TextPage";
  9.    static var version = "0.0.0.1";
  10.    static var __maxPageHeight = 376;
  11.    static var __pageBorder = 5;
  12.    static var __vSpacing = 5;
  13.    static var __hSpacing = 5;
  14.    var __nextDepth = 1;
  15.    function TextPage()
  16.    {
  17.       super();
  18.       mx.events.EventDispatcher.initialize(this);
  19.    }
  20.    function set enabled(activeStatus)
  21.    {
  22.       if(activeStatus == true)
  23.       {
  24.          var _loc2_ = new TextFormat();
  25.          _loc2_.color = 0;
  26.          var _loc4_ = "<headline>" + this.__title.htmlText.slice(18,this.__title.htmlText.length - 19) + "</headline>";
  27.          this.__title.setTextFormat(_loc2_);
  28.          this.__title.setNewTextFormat(_loc2_);
  29.          this.__title.htmlText = _loc4_;
  30.       }
  31.       else
  32.       {
  33.          _loc2_ = new TextFormat();
  34.          _loc2_.color = 8421504;
  35.          _loc4_ = "<headlinedisabled>" + this.__title.htmlText.slice(10,this.__title.htmlText.length - 11) + "</headlinedisabled>";
  36.          this.__title.setTextFormat(_loc2_);
  37.          this.__title.setNewTextFormat(_loc2_);
  38.          this.__title.htmlText = _loc4_;
  39.       }
  40.       this.__body.enabled = activeStatus;
  41.       this.__body.label.selectable = false;
  42.       if(activeStatus == true)
  43.       {
  44.       }
  45.    }
  46.    function init(Void)
  47.    {
  48.       super.init();
  49.    }
  50.    function size(Void)
  51.    {
  52.       super.size();
  53.    }
  54.    function doneSetting()
  55.    {
  56.       this.sendMessage("pageReady");
  57.    }
  58.    function set title(newTitle)
  59.    {
  60.       function workingLayout(bodyText, width, targetObject)
  61.       {
  62.          trace("targetObject: " + targetObject);
  63.          var titleFormat = _level0.styleSheetToTextFormat(_global.textStyles.getStyle("headline"));
  64.          targetObject.html = true;
  65.          with(targetObject)
  66.          {
  67.             embedFonts = true;
  68.             setTextFormat(titleFormat);
  69.             setNewTextFormat(titleFormat);
  70.             styleSheet = _global.textStyles;
  71.             border = false;
  72.             selectable = false;
  73.             autoSize = true;
  74.             borderColor = 13421772;
  75.             multiline = true;
  76.             wordWrap = true;
  77.          }
  78.          var oneRowMetrics = titleFormat.getTextExtent("a",width);
  79.          var twoRowMetrics = titleFormat.getTextExtent("a\na",width);
  80.          var tfhIncrement = twoRowMetrics.textFieldHeight - oneRowMetrics.textFieldHeight;
  81.          var metrics = titleFormat.getTextExtent(bodyText,width);
  82.          var finalHtmlText = "<headline><textformat leading=\'" + myLeading + "\'>" + bodyText + "</textformat></headline>";
  83.          targetObject.htmlText = finalHtmlText;
  84.          var positiveLeading = myLeading >= 0 ? myLeading : - myLeading;
  85.          var calculatedHeight = targetObject._height;
  86.          targetObject.autoSize = false;
  87.          targetObject._height = metrics.textFieldHeight + 1;
  88.          targetObject.htmlText = "<headline><textformat leading=\'0\'>" + bodyText + "</textformat></headline>";
  89.          var unleadedTextHeight1 = targetObject.textHeight;
  90.          var unleadedFieldHeight = targetObject._height;
  91.          targetObject.htmlText = "<headline><textformat leading=\'-1\'>" + bodyText + "</textformat></headline>";
  92.          var unleadedTextHeight2 = targetObject.textHeight;
  93.          var numRows = unleadedTextHeight2 - unleadedTextHeight1;
  94.          numRows = numRows >= 0 ? numRows : - numRows;
  95.          trace("numRows of text: " + numRows);
  96.          targetObject.htmlText = finalHtmlText;
  97.          trace("FINAL TEXTPAGE TITLE: " + finalHtmlText);
  98.          targetObject._height = 38;
  99.       }
  100.       this.createTextField("__title",this.__nextDepth,TextPage.__pageBorder,TextPage.__pageBorder,540,50);
  101.       this.__nextDepth = this.__nextDepth + 1;
  102.       var myLeading = -5;
  103.       var titleFormat = _level0.styleSheetToTextFormat(_global.textStyles.getStyle("headline"));
  104.       workingLayout(newTitle,365,this.__title);
  105.    }
  106.    function set body(bodyText)
  107.    {
  108.       trace("----- TextPage.body -----");
  109.       if(this.__body == undefined)
  110.       {
  111.          this.__body = this.createClassObject(mx.controls.TextArea,"primaryDesc",this.__nextDepth);
  112.          this.__body.editable = false;
  113.          this.__body.label.selectable = false;
  114.          this.__body.wordWrap = true;
  115.          this.__body.borderStyle = "none";
  116.          this.__body.html = true;
  117.          this.__body.embedFonts = true;
  118.          this.__body.styleSheet = _global.textStyles;
  119.          this.__body.setStyle("styleName","scrollTextAreaStyle");
  120.          this.__nextDepth = this.__nextDepth + 1;
  121.       }
  122.       if(this.__body.text != bodyText)
  123.       {
  124.          this.__body.text = "<pagebody>" + bodyText + "</pagebody>";
  125.          this.__body._x = TextPage.__pageBorder;
  126.          this.__body._y = this.__title._y + this.__title._height + 2 * TextPage.__vSpacing - 12;
  127.          this.__body.setSize(550,TextPage.__maxPageHeight);
  128.       }
  129.       trace("----- end of TextPage.body -----");
  130.    }
  131.    function removeHTMLTags(htmlText)
  132.    {
  133.       var _loc6_ = function(txt, index)
  134.       {
  135.          return txt.indexOf("<",index);
  136.       };
  137.       var _loc8_ = function(txt, index)
  138.       {
  139.          return txt.indexOf(">",index);
  140.       };
  141.       var _loc2_ = new Array();
  142.       var _loc7_ = 0;
  143.       var _loc9_ = undefined;
  144.       var _loc10_ = undefined;
  145.       while(_loc7_ < htmlText.length)
  146.       {
  147.          _loc9_ = _loc6_(htmlText,_loc7_);
  148.          if(_loc9_ == -1)
  149.          {
  150.             break;
  151.          }
  152.          _loc10_ = _loc8_(htmlText,_loc9_);
  153.          var _loc3_ = _loc6_(htmlText,_loc10_);
  154.          while(_loc3_ == _loc10_ + 1)
  155.          {
  156.             _loc10_ = _loc8_(htmlText,_loc3_);
  157.             _loc3_ = _loc6_(htmlText,_loc10_);
  158.          }
  159.          _loc2_.push({start:_loc9_,end:_loc10_});
  160.          _loc7_ = _loc10_ + 1;
  161.       }
  162.       var _loc5_ = 0;
  163.       while(_loc5_ < _loc2_.length)
  164.       {
  165.          _loc9_ = _loc2_[_loc5_].start;
  166.          var _loc11_ = htmlText.charAt(_loc2_[_loc5_].start);
  167.          _loc10_ = _loc2_[_loc5_].end;
  168.          var _loc12_ = htmlText.charAt(_loc2_[_loc5_].end);
  169.          var _loc16_ = htmlText.substring(_loc9_ + 1,_loc10_);
  170.          _loc5_ = _loc5_ + 1;
  171.       }
  172.       if(_loc2_.length != 0)
  173.       {
  174.          var _loc18_ = "";
  175.          if(_loc2_[0].start > 0)
  176.          {
  177.             _loc18_ += htmlText.substring(0,_loc2_[0].start);
  178.          }
  179.          var _loc4_ = 0;
  180.          while(_loc4_ < _loc2_.length - 1)
  181.          {
  182.             var _loc13_ = _loc2_[_loc4_].end + 1;
  183.             var _loc15_ = _loc2_[_loc4_ + 1].start;
  184.             _loc18_ += htmlText.substring(_loc2_[_loc4_].end + 1,_loc2_[_loc4_ + 1].start);
  185.             _loc4_ = _loc4_ + 1;
  186.          }
  187.          if(_loc2_[_loc2_.length - 1].end < htmlText.length - 1)
  188.          {
  189.             _loc18_ += htmlText.substring(_loc2_[_loc2_.length - 1].end + 1);
  190.          }
  191.          return _loc18_;
  192.       }
  193.       return htmlText;
  194.    }
  195.    function sendMessage(p_msgtxt)
  196.    {
  197.       var _loc2_ = {target:this,type:"pageReady"};
  198.       _loc2_.msgtxt = p_msgtxt;
  199.       _loc2_.pageType = "TextPage";
  200.       this.dispatchEvent(_loc2_);
  201.    }
  202. }
  203.